package com.jk.controller.sunshine;

import com.jk.dto.JsonResult;
import com.jk.util.JsonUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.*;

/**
 * Created by yanghuan on 2015/12/28.
 */
@Controller
@RequestMapping("/sunshine/show")
public class ShowController {

    @RequestMapping("")
    public String page(HttpServletRequest request, ModelMap modelMap) {
        ServletContext context = request.getSession().getServletContext();
        List<Map<String, String>> mapList = new ArrayList<Map<String, String>>();
        String imgThumbsRelativePath = context.getRealPath("static/show/images/thumbs");
        File file = new File(imgThumbsRelativePath);
        if (file.exists() && file.isDirectory()) {
            File[] files = file.listFiles();
            for (File f : files) {
                Map<String, String> map = new HashMap<String, String>();
                String fileName = f.getName();
                map.put("imgName", fileName);
                mapList.add(map);
            }
        }
        modelMap.put("imgList", mapList);
        return "sunshine/show";
    }

}
